package com.ricervcvcer.user.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ricervcvcer.user.entity.SysRight;
import com.ricervcvcer.user.vo.MenuNode;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author moge
 * @since 2022-01-10
 */
public interface SysRightMapper extends BaseMapper<SysRight> {
    @Select("select \n" +
            "            distinct r.right_code, r.right_icon, r.right_text, r.right_type, r.right_url, r.right_tip,r.right_parent \n" +
            "            from sys_user usr left join sys_role role\n" +
            "on usr.usr_role_id=role.role_id\n" +
            "left join sys_role_right rr on role.role_id=rr.rf_role_id\n" +
            "            left join sys_right r on r.right_code = rr.rf_right_code \n" +
            "            where r.right_parent = #{rightParent} and usr.usr_id = #{usrId}\n" +
            "            order by r.right_code asc")
    List<MenuNode> selectMenu(@Param("rightParent") String rightParent,@Param("usrId") Integer usrId);

    @Select("select \n" +
            "            distinct r.right_code, r.right_icon,r.right_text, r.right_type, r.right_url, r.right_tip,r.right_parent \n" +
            "            from sys_right r \n" +
            "            left join sys_role_right rr on r.right_code = rr.rf_right_code\n" +
            "            where r.right_parent = #{rightParent}\n" +
            "            order by r.right_code asc")
    List<MenuNode> selectMenu2(@Param("rightParent") String rightParent);
}
